package com.tianyalei.wolf.sample;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.tianyalei.wolf.mddesignlib.snackbar.AbSnackBarUtil;
import com.tianyalei.wolf.mddesignlib.utils.ToastUtil;
import com.tianyalei.wolf.mddesignlib.view.dialog.MaterialDialog;
import com.tianyalei.wolf.sample.activity.activityanim.AnimActivity;
import com.tianyalei.wolf.sample.activity.adapter.EnterActivity;
import com.tianyalei.wolf.sample.activity.banner.BannerActivity;
import com.tianyalei.wolf.sample.activity.bottomnavigation.BottomNavigationActivity;
import com.tianyalei.wolf.sample.activity.collapsing.CollChooseActivity;
import com.tianyalei.wolf.sample.activity.imageload.ImageLoadActivity;
import com.tianyalei.wolf.sample.activity.tablayout.TabActivity;
import com.tianyalei.wolf.sample.activity.tablayout.TabBottomActivity;
import com.tianyalei.wolf.sample.activity.toolbar.ToolBarActivity;
import com.tianyalei.wolf.sample.activity.uppai.UploadFileActivity;
import com.tianyalei.wolf.sample.activity.wxcircle.WXCircleActivityNew;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @Bind(R.id.snackbar_normal)
    TextView snackBar;

    @Bind(R.id.navigation_view)
    NavigationView navigationView;
    @Bind(R.id.drawerlayout)
    DrawerLayout mDrawerLayout;

    private ActionBarDrawerToggle mActionBarDrawerToggle;

    @Bind(R.id.toolbar)
    Toolbar mToolbar;

    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        setSupportActionBar(mToolbar);
        //设置标题的颜色
        mToolbar.setTitleTextColor(getResources().getColor(R.color.white));

        mContext = this;
        mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.app_name,
                R.string.app_name) {
            @Override
            public void onDrawerClosed(View drawerView) {
                invalidateOptionsMenu();
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                invalidateOptionsMenu();
            }
        };
        mActionBarDrawerToggle.syncState();
        mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);

        navigationView.setNavigationItemSelectedListener(
                new NavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected(MenuItem menuItem) {
                        menuItem.setChecked(true);
                        mDrawerLayout.closeDrawers();
                        return true;
                    }
                });
    }

    @OnClick({R.id.snackbar_normal, R.id.open_menu, R.id.snackbar_action, R.id.bottom_tab_layout, R.id.tab_layout,
            R.id.toolbar_tv, R.id.imageload, R.id.wxcircle, R.id.coordinator, R.id.material_dialog, R.id.activity_anim,
            R.id.activity_adapter, R.id.activity_banner, R.id.bottom_navigation, R.id.imageupload})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.snackbar_normal:
                AbSnackBarUtil.showSnackBar(snackBar, "我是普通的SnackBar");
                break;
            case R.id.snackbar_action:
                AbSnackBarUtil.showSnackBarAction(snackBar, "我是带action的SnackBar", "点我", new AbSnackBarUtil.SnackClickListener() {
                    @Override
                    public void action() {
                        ToastUtil.showToast(mContext, "我被点了");
                    }
                });
                break;
            case R.id.bottom_tab_layout:
                startActivity(new Intent(mContext, TabBottomActivity.class));
                break;
            case R.id.bottom_navigation:
                startActivity(new Intent(mContext, BottomNavigationActivity.class));
                break;
            case R.id.imageupload:
                startActivity(new Intent(mContext, UploadFileActivity.class));
                break;
            case R.id.tab_layout:
                startActivity(new Intent(mContext, TabActivity.class));
                break;
            case R.id.open_menu:
                mDrawerLayout.openDrawer(navigationView);
                break;
            case R.id.toolbar_tv:
                startActivity(new Intent(mContext, ToolBarActivity.class));
                break;
            case R.id.material_dialog:
                final MaterialDialog mMaterialDialog;
                mMaterialDialog = new MaterialDialog(this);
                mMaterialDialog.setMessage(
                        "Hi! Th. ^ ^")
                        //mMaterialDialog.setBackgroundResource(R.drawable.background);
                        .setPositiveButton("OK", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mMaterialDialog.dismiss();
                                ToastUtil.showToast(mContext, "OK");
                            }
                        })
                        .setNegativeButton("CANCEL",
                                new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        mMaterialDialog.dismiss();
                                        ToastUtil.showToast(mContext, "Cancel");
                                    }
                                })
                        .setCanceledOnTouchOutside(true)
                        // You can change the message anytime.
                        // mMaterialDialog.setTitle("提示");
                        .setOnDismissListener(
                                new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialog) {
                                        ToastUtil.showToast(mContext, "onDismiss");
                                    }
                                })
                        .show();
                break;
            case R.id.imageload:
                startActivity(new Intent(mContext, ImageLoadActivity.class));
                break;
            case R.id.wxcircle:
                //图片详细页在同一个界面
//                startActivity(new Intent(mContext, WXCircleActivity.class));
                //图片详细页切界面了
                startActivity(new Intent(mContext, WXCircleActivityNew.class));
                break;
            case R.id.coordinator:
                startActivity(new Intent(mContext, CollChooseActivity.class));
                break;
            case R.id.activity_anim:
                startActivity(new Intent(mContext, AnimActivity.class));
                break;
            case R.id.activity_adapter:
                startActivity(new Intent(mContext, EnterActivity.class));
                break;
            case R.id.activity_banner:
                startActivity(new Intent(mContext, BannerActivity.class));
                break;
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (mActionBarDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mActionBarDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mActionBarDrawerToggle.onConfigurationChanged(newConfig);
    }

    public void closeDrawer() {
        mDrawerLayout.closeDrawers();
    }

}
